package com.ds.robot.assistant.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 作用：
 *
 * @author WeiShaoying
 * 
 */
@Component
// @RequiredArgsConstructor
@Slf4j
public class HolidayServiceContext {

    private final Map<String, HolidayService> holidayServiceMap;

    @Value("${holiday.service.strategy}")
    private String serviceName;

    @Autowired
    public HolidayServiceContext(Map<String, HolidayService> holidayServiceMap) {
        this.holidayServiceMap = holidayServiceMap;
        log.info("HolidayServiceContext init, holidayServiceMap: {}", holidayServiceMap);
    }

    // @Autowired
    public HolidayServiceContext(List<HolidayService> holidayServiceList) {
        this.holidayServiceMap = holidayServiceList.stream().collect(Collectors.toMap(service -> service.getClass().getName(), Function.identity()));
    }

    public boolean isWorkDay(String date) {
        return holidayServiceMap.get(serviceName).isWorkDay(date);
    }

    public boolean isRestDay(String date) {
        return holidayServiceMap.get(serviceName).isRestDay(date);
    }

    public boolean isHoliday(String date) {
        return holidayServiceMap.get(serviceName).isHoliday(date);
    }
}
